package oo

import (
	"github.com/elliotchance/pie/v2"
	"strconv"
	"strings"
)

type Substring struct {
	String
}

func (o *Substring) IntsV1() []int {
	ss := o.split()
	var number Number
	return pie.OfOrdered(ss).Filter(func(s string) bool {
		return number.IsInt(s)
	}).Ints()
}

func (o *Substring) IntsV2() []int {
	ss := o.split()

	var values []int
	for _, s := range ss {
		value, err := strconv.Atoi(s)
		if err == nil {
			values = append(values, value)
		}
	}
	return values
}

func (o *Substring) split() []string {
	return strings.Split(o.value, ",")
}
